package com.cs.base.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.cs.base.R;
import com.cs.base.databinding.DialogLoadingBinding;

/**
 * @ClassName: LoadingDialog
 * @Date: 2021/6/16
 * @Author: CS
 * @Description: 加载框
 */
public class LoadingDialog extends BaseDialog<DialogLoadingBinding> {

    //提示信息
    private String msg;

    public LoadingDialog(Context context) {
        super(context);
    }

    @Override
    protected void initView() {
        int progressColor = context.getResources().getColor(R.color.gray_3);
        binding.progressbar.getIndeterminateDrawable().setColorFilter(progressColor, android.graphics.PorterDuff.Mode.SRC_IN);
        if(TextUtils.isEmpty(msg)){
            binding.tvLoading.setVisibility(View.GONE);
        }else {
            binding.tvLoading.setText(msg);
            binding.tvLoading.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected DialogLoadingBinding getViewBinding() {
        return DialogLoadingBinding.inflate(getLayoutInflater());
    }

    public void setLoadingMsg(String msg){
        if(isShowing()){
            if(TextUtils.isEmpty(msg)){
                binding.tvLoading.setVisibility(View.GONE);
            }else {
                binding.tvLoading.setText(msg);
                binding.tvLoading.setVisibility(View.VISIBLE);
            }
        }else {
            this.msg=msg;
        }
    }

}
